# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=faad2
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.8.8
pkgrel=1
pkgdesc="ISO AAC audio decoder (mingw-w64)"
arch=('any')
url="http://www.audiocoding.com/"
license=('GPL')
options=('staticlibs' 'strip')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-yasm" "${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
source=("https://downloads.sourceforge.net/sourceforge/faac/${_realname}-${pkgver}.tar.gz"
        "fix-mingw-build.patch")
sha256sums=('985c3fadb9789d2815e50f4ff714511c79c2710ac27a4aaaf5c0c2662141426d'
            '02f122391eeca2f79215b785e5ac97d2a24edd25b0e74b8f8f5f985f076a8e1d')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/fix-mingw-build.patch"

  WANT_AUTOMAKE=latest autoreconf --force --install
}

build() {
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  mkdir -p "${srcdir}"/build-${MINGW_CHOST} && cd "${srcdir}"/build-${MINGW_CHOST}
  cp -rf ../${_realname}-${pkgver}/* .

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make check
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
